//
//  LWDiscoverViewController.m
//  1.28  weibo
//
//  Created by mac on 15/1/30.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "LWDiscoverViewController.h"
#import "LWSearchBar.h"

@interface LWDiscoverViewController () <UITextFieldDelegate>
//@property (nonatomic,weak) UITextField *search;
@property (nonatomic,weak) LWSearchBar *search;
@end

@implementation LWDiscoverViewController

- (void)viewDidLoad{

    [super viewDidLoad];
    LWSearchBar *searchTf = [[LWSearchBar alloc] init];
    searchTf.frame = CGRectMake(0, 0, 300, 30);
    
    searchTf.delegate = self;
    self.search = searchTf;
    self.navigationItem.titleView = searchTf;
}

#pragma mark - UITextFieldDelegate的代理方法
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    
    //1.添加右侧按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)];
    //2.TextField的左侧图片的View
   self.search.leftIconName = @"settings_statistic_triangle";

}

- (void)cancel{
    
    self.navigationItem.rightBarButtonItem = nil;
    [[UIApplication sharedApplication].keyWindow endEditing:YES];
    self.search.leftIconName = @"searchbar_searchlist_search_icon";

}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{

    [[UIApplication sharedApplication].keyWindow endEditing:YES];
    self.search.leftIconName = @"searchbar_searchlist_search_icon";
    self.navigationItem.rightBarButtonItem = nil;
}

@end


